package bairui.international.weixin.portal.miniapp.controller.product.product;

import java.util.List;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.querydsl.QSort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.domain.jpa.TB_ProductCategory;
import bairui.international.service.Service_ProductCategory;
import lombok.Getter;

/**
 *
 * 分类列表
 *
 * @generated
 * 
 * @see STest_C_Product_CategoryList_Get 测试
 *
 */
@Controller
public class C_Product_CategoryList_Get
 extends SC_Product_CategoryList_Get 
{
	
	@Autowired private Service_ProductCategory service_ProductCategory;
	
	/**
	 * Get请求
	 */
	@Action(Get.class)
	@GetMapping(Get.RequestMappingValue)
	public @FomatOutput @ResponseBody Object get(
		ModelMap map, HttpServletRequest request,
		@RequestParam String rootCategoryName,
		@RequestParam String skey
	) throws Exception {
		List<TB_ProductCategory> list = service_ProductCategory.list(
				it->it.parent.name.eq(rootCategoryName),
				it->new QSort(it.orderValue.desc())
			).getContent();
		return list
				.stream()
				.map(it->new Output(it))
				.collect(Collectors.toList());
	}
	
	public static class Output {
		@Getter private Long id;
		@Getter private String name;
		
		public Output(TB_ProductCategory category){
			this.id = category.getId();
			this.name = category.getName();
		}
	}
	

}
